<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\user_center\logic\user;
use think\facade\Hook;

class AuthTokenlogic{

	/**
     * 生成token
     * @param  int $uid  用户id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function create_authtoken($uid){
    	//生成
    	$access_token_expire_time = 7200;//config();
    	$access_token_expire_in   = time()+$access_token_expire_time;//到期时间
    	$access_token = base64_encode(md5($uid.microtime().$access_token_expire_in.'xm_access'));
    	$refresh_token_expire_time = 72000;//config();
    	$refresh_token_expire_in   = time()+$refresh_token_expire_time;//到期时间
    	$refresh_token = base64_encode(md5($uid.microtime().$refresh_token_expire_in.'xm_refresh'));
    	dump($access_token);dump($refresh_token);
    	//入库
    	$UcMemberAuthtoken = model('UcMemberAuthtoken', 'model\user');
    	$UcMemberAuthtoken -> where('uid = 2') -> find();
    	$data = [];
    	$data['access_token_expire_in']  = $access_token_expire_in;
    	$data['refresh_token_expire_in'] = $refresh_token_expire_in;
    	$data['access_token'] 			 = $access_token;
    	$data['refresh_token'] 			 = $refresh_token;
    	$map = [];
    	$map['uid'] = $uid;
    	//dump($data);dump($map);die();
    	$res = $UcMemberAuthtoken->save($data, $map);
dump($UcMemberAuthtoken -> getLastSql(1));
    	dump($res);
    }

}